package com.jams.goodox.activity.home;

import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.jams.goodox.BaseActivity;
import com.jams.goodox.R;
import com.jams.goodox.utils.StyleUtil;
import com.jams.library.commonAdapter.ListCommonAdapter;
import com.jams.library.commonAdapter.ListCommonViewHolder;
import com.jams.library.fresco.FrescoUtil;

import butterknife.Bind;

/**
 * Created by Administrator on 2017/10/8.
 */

public class OrderFlowActivity extends BaseActivity {
    @Bind(R.id.sdv_baokuan)
    SimpleDraweeView sdvBaokuan;
    @Bind(R.id.tx_baokuan)
    TextView txBaokuan;
    @Bind(R.id.tx_order_number)
    TextView txOrderNumber;
    @Bind(R.id.scroll_list)
    ListView scrollList;
    @Bind(R.id.tx_info)
    TextView tx_info;

    private ListCommonAdapter listCommonAdapter;
    private OrderResp.DataBean orderBean;

    @Override
    protected int getLayoutId() {
        return R.layout.order_flow_activity;
    }

    @Override
    protected void init() {
        StyleUtil.titleBackKey(this,"订单流程");
        orderBean=(OrderResp.DataBean)getIntent().getSerializableExtra("orderBean");
        if(orderBean==null||orderBean.getProduct().size()==0)return;
        FrescoUtil.loadNetUrl(sdvBaokuan,orderBean.getProduct().get(0).getPreview());
        txBaokuan.setText(String.format("%s件商品",orderBean.getProduct().size()));
        txOrderNumber.setText(String.format("订单号：%s",orderBean.getOrdersn()));
        StringBuilder sb=new StringBuilder();
        sb.append(String.format("订单总价：%s\n",orderBean.getPayable()));
        if(orderBean.getProduct()!=null){
            for(int i=0,len=orderBean.getProduct().size();i<len;i++){
                OrderResp.DataBean.ProductBean productBean=orderBean.getProduct().get(i);
                sb.append(String.format("%s *%s",productBean.getTitle(),productBean.getNum()));
//                for(int j=0,lenJ=productBean.getOption().size();j<lenJ;j++){
//                    GoodBuyBean.Data.OptionBean optionBean=productBean.getOption().get(j);
//                    sb.append(String.format("%s：%s",optionBean.getOptionKey(),optionBean.getName()));
//                    if(i==len-1&&j==lenJ-1)break;
//                    else sb.append("\n");
//                }
            }
        }
        tx_info.setText(sb);
        setScrollList();
    }

    private void setScrollList(){
        if(orderBean.getProcess()==null)return;
        listCommonAdapter=new ListCommonAdapter<OrderResp.DataBean.ProcessBean>(this,orderBean.getProcess(),R.layout.order_flow_item) {
            @Override
            public void convert(ListCommonViewHolder helper, OrderResp.DataBean.ProcessBean item, int position) {
                helper.setViewVisible(R.id.view_line_top,position!=0);
                View view_line_top=helper.getView(R.id.view_line_top);
                view_line_top.setVisibility(position==0?View.INVISIBLE:View.VISIBLE);
                helper.setViewVisible(R.id.view_line_bottom,position!=orderBean.getProcess().size()-1);
                View view_circle=helper.getView(R.id.view_circle);
                if(position==orderBean.getProcess().size()-1){
                    view_circle.setBackgroundResource(R.drawable.bg_circle_red);
                }else {
                    view_circle.setBackgroundResource(R.drawable.bg_circle_gray);
                }
                helper.setText(R.id.tx_order_submit,item.getTitle());
                helper.setText(R.id.tx_order_time,item.getTime());
            }
        };
        scrollList.setAdapter(listCommonAdapter);
    }

}
